package com.egao.ap.biz.impl;

import com.egao.ap.entity.Settings;
import com.egao.common.core.damon.constant.UserConstant;
import com.egao.common.core.damon.results.BaseDao;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.damon.utils.Utils;
import com.egao.common.system.entity.User;
import com.egao.ap.biz.InformationBiz;
import com.egao.ap.entity.Information;
import com.egao.common.core.web.JsonResult;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 *
 * 数据层实现类
 * @author : Doman
 * @date : 2020-10-12 14:21:51
 * @version ：1.0
 */
@Repository
public class InformationBizImpl extends BaseDao implements InformationBiz {

	@Override
	public JsonResult list(PageResult2<T> page, Information information) throws Exception {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
		StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
        sql.append(",i.userAvatar,i.userNickName");
        sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",(select count(1) from a_information_zan za where za.infoid=i.id) zanCount");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.username createName ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 ");
        sql.append(" and 1=2 ");
    	if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
			if(Utils.isNotEmpty(information.getType())){
				sql.append(" and i.type=:type  ");
				map.put("type", information.getType());
			}
			if(Utils.isNotEmpty(information.getAge())){
				if(information.getAge().equals("00后")){
					sql.append(" and i.age>'2000-01-01'  ");
				} else if(information.getAge().equals("95后")){
					sql.append(" and (i.age>'1995-01-01' and i.age<'2000-01-01' ) ");
				} else if(information.getAge().equals("90后")){
					sql.append(" and (i.age>'1990-01-01' and i.age<'1995-01-01' ) ");
				} else if(information.getAge().equals("85后")){
					sql.append(" and (i.age>'1985-01-01' and i.age<'1990-01-01' ) ");
				} else if(information.getAge().equals("80后")){
					sql.append(" and (i.age>'1980-01-01' and i.age<'1985-01-01' ) ");
				} else if(information.getAge().equals("75后")){
					sql.append(" and (i.age>'1975-01-01' and i.age<'1980-01-01' ) ");
				} else if(information.getAge().equals("70后")){
					sql.append(" and (i.age>'1970-01-01' and i.age<'1975-01-01' ) ");
				} else {
					sql.append(" and i.age<'1970-01-01' ");
				}
			}
			if(Utils.isNotEmpty(information.getGender()) && !information.getGender().equals("0")){
				sql.append(" and i.gender=:gender  ");
				map.put("gender", information.getGender());
			}
			if(Utils.isNotEmpty(information.getEducation())){
				sql.append(" and instr(i.education,:education)>0  ");
				map.put("education", information.getEducation());
			}
			if(Utils.isNotEmpty(information.getKeywords())){
				sql.append(" and (instr(i.userNickName,:keywords)>0 or instr(i.nickname,:keywords)>0 or instr(i.phone,:keywords)>0) ");
				map.put("keywords", information.getKeywords());
			}
			if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
                sql.append(" order by i."+information.getSort()+" "+information.getOrder());
            } else {
                sql.append(" order by i.update_time desc");
            }
		}
		return jsonResult(getPageQueryList(page, sql.toString(), map, rm));
	}

	@Override
	public JsonResult list(PageResult2<T> page, Information information, User loginUser) throws Exception {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
		StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
		sql.append(",i.userAvatar,i.userNickName");
		sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",(select count(1) from a_information_zan za where za.infoid=i.id) zanCount");
		sql.append(",zan.id zanId");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
		sql.append(",sogzn.organization_name organizationName,suser.username createName ");
		sql.append(" from a_information i ");
		sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
		sql.append(" left join a_information_zan zan on zan.infoid=i.id and zan.openid=:openid");
		sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
		sql.append(" where i.deleted=0  and sogzn.deleted=0 ");
		map.put("openid", loginUser.getXcxopenid());
		if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
			if(Utils.isNotEmpty(loginUser.getAdmin()) && (loginUser.getAdmin().equals("1")|| loginUser.getAdmin().equals("2"))) {
			}else if(Utils.isNotEmpty(loginUser.getXcxopenid())) {
				sql.append(" and i.openid=:openid  ");
				map.put("openid", loginUser.getXcxopenid());
			} else {
				sql.append(" and 1=2  ");
			}
			if(Utils.isNotEmpty(information.getType()) && !(Utils.isNotEmpty(loginUser.getAdmin()) && (loginUser.getAdmin().equals("1")))){
//			if(Utils.isNotEmpty(information.getType()) && !(Utils.isNotEmpty(loginUser.getAdmin()) && (loginUser.getAdmin().equals("1")|| loginUser.getAdmin().equals("2")))){
//			if(Utils.isNotEmpty(information.getType()) && !loginUser.getXcxopenid().equals("oEML05EM2NltKrGyjzpL34DmVj6E")){
				sql.append(" and i.type=:type  ");
				map.put("type", information.getType());
			}
			if(Utils.isNotEmpty(information.getAge())){
				if(information.getAge().equals("00后")){
					sql.append(" and i.age>'2000-01-01'  ");
				} else if(information.getAge().equals("95后")){
					sql.append(" and (i.age>'1995-01-01' and i.age<'2000-01-01' ) ");
				} else if(information.getAge().equals("90后")){
					sql.append(" and (i.age>'1990-01-01' and i.age<'1995-01-01' ) ");
				} else if(information.getAge().equals("85后")){
					sql.append(" and (i.age>'1985-01-01' and i.age<'1990-01-01' ) ");
				} else if(information.getAge().equals("80后")){
					sql.append(" and (i.age>'1980-01-01' and i.age<'1985-01-01' ) ");
				} else if(information.getAge().equals("75后")){
					sql.append(" and (i.age>'1975-01-01' and i.age<'1980-01-01' ) ");
				} else if(information.getAge().equals("70后")){
					sql.append(" and (i.age>'1970-01-01' and i.age<'1975-01-01' ) ");
				} else {
					sql.append(" and i.age<'1970-01-01' ");
				}
			}
			if(Utils.isNotEmpty(information.getGender()) && !information.getGender().equals("0")){
				sql.append(" and i.gender=:gender  ");
				map.put("gender", information.getGender());
			}
			if(Utils.isNotEmpty(information.getEducation())){
				sql.append(" and instr(i.education,:education)>0  ");
				map.put("education", information.getEducation());
			}
			if(Utils.isNotEmpty(information.getKeywords())){
				sql.append(" and (instr(i.userNickName,:keywords)>0 or instr(i.nickname,:keywords)>0 or instr(i.phone,:keywords)>0) ");
				map.put("keywords", information.getKeywords());
			}
			if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
				sql.append(" order by i."+information.getSort()+" "+information.getOrder());
			} else {
				sql.append(" order by i.update_time desc");
			}
		}
		return jsonResult(getPageQueryList(page, sql.toString(), map, rm));
	}


	@Override
	public List<Information> list(Information information, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
        StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
		sql.append(",i.userAvatar,i.userNickName");
        sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.username createName ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 ");
		if(loginUser.getUserId() != UserConstant.ADMIN_ID){
            sql.append(" and i.organization_id=:tableOrganizationId ");
            map.put("tableOrganizationId", loginUser.getOrganizationId() + "");
        }
    	if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
//			if(Utils.isNotEmpty(information.getName())){
//				sql.append(" and instr(i.name,:name)>0 ");
//				map.put("name", information.getName());
//			}
            if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
				sql.append(" order by i."+information.getSort()+" "+information.getOrder());
			} else {
				sql.append(" order by i.update_time desc");
			}
		}
		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public List<Information> list(Information information) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
        StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
		sql.append(",i.userAvatar,i.userNickName");
        sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.username createName ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 ");

    	if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
			if(Utils.isNotEmpty(information.getAge())){
				if(information.getAge().equals("00后")){
					sql.append(" and i.age>'2000-01-01'  ");
				} else if(information.getAge().equals("95后")){
					sql.append(" and (i.age>'1995-01-01' and i.age<'2000-01-01' ) ");
				} else if(information.getAge().equals("90后")){
					sql.append(" and (i.age>'1990-01-01' and i.age<'1995-01-01' ) ");
				} else if(information.getAge().equals("85后")){
					sql.append(" and (i.age>'1985-01-01' and i.age<'1990-01-01' ) ");
				} else if(information.getAge().equals("80后")){
					sql.append(" and (i.age>'1980-01-01' and i.age<'1985-01-01' ) ");
				} else if(information.getAge().equals("75后")){
					sql.append(" and (i.age>'1975-01-01' and i.age<'1980-01-01' ) ");
				} else if(information.getAge().equals("70后")){
					sql.append(" and (i.age>'1970-01-01' and i.age<'1975-01-01' ) ");
				} else {
					sql.append(" and i.age<'1970-01-01' ");
				}
			}
			if(Utils.isNotEmpty(information.getGender()) && !information.getGender().equals("0")){
				sql.append(" and i.gender=:gender  ");
				map.put("gender", information.getGender());
			}
			if(Utils.isNotEmpty(information.getEducation())){
				if(information.getEducation().equals("博士")){
					sql.append(" and instr(i.education,'博士')>0  ");
				} else if(information.getEducation().equals("硕士")){
					sql.append(" and (instr(i.education,'硕士')>0 or instr(i.education,'研究生')>0 )  ");
				} else if(information.getEducation().equals("本科")){
					sql.append(" and instr(i.education,'本科')>0  ");
				} else if(information.getEducation().equals("大专")){
					sql.append(" and instr(i.education,'大专')>0  ");
				} else {
					sql.append(" and (instr(i.education,'博士')=0 and instr(i.education,'硕士')=0 " +
							"and instr(i.education,'研究生')=0 and instr(i.education,'本科')=0and instr(i.education,'大专')=0 ) ");
				}
				map.put("education", information.getEducation());
			}
			if(Utils.isNotEmpty(information.getKeywords())){
				sql.append(" and (instr(i.userNickName,:keywords)>0 or instr(i.nickname,:keywords)>0 or instr(i.phone,:keywords)>0) ");
				map.put("keywords", information.getKeywords());
			}
			if(Utils.isNotEmpty(information.getMarriage())){
				sql.append(" and i.marriage=:marriage  ");
				map.put("marriage", information.getMarriage());
			}
			if(Utils.isNotEmpty(information.getPic())){
				if (information.getPic().equals("有")) {
					sql.append(" and pic is not null and pic !=''  ");
				} else {
					sql.append(" and (pic is null or pic ='')  ");
				}
			}
			/*if(Utils.isNotEmpty(information.getPic())){
				sql.append(" and pic is not null and pic !=''  ");
			}*/
            if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
				sql.append(" order by i."+information.getSort()+" "+information.getOrder());
			} else {
				sql.append(" order by i.update_time desc");
			}
		}
		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public List<Information> appList(Information information) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
        StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
        sql.append(",i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 ");

    	if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
			if(Utils.isNotEmpty(information.getAge())){
				if(information.getAge().equals("00后")){
					sql.append(" and i.age>'2000-01-01'  ");
				} else if(information.getAge().equals("95后")){
					sql.append(" and (i.age>'1995-01-01' and i.age<'2000-01-01' ) ");
				} else if(information.getAge().equals("90后")){
					sql.append(" and (i.age>'1990-01-01' and i.age<'1995-01-01' ) ");
				} else if(information.getAge().equals("85后")){
					sql.append(" and (i.age>'1985-01-01' and i.age<'1990-01-01' ) ");
				} else if(information.getAge().equals("80后")){
					sql.append(" and (i.age>'1980-01-01' and i.age<'1985-01-01' ) ");
				} else if(information.getAge().equals("75后")){
					sql.append(" and (i.age>'1975-01-01' and i.age<'1980-01-01' ) ");
				} else if(information.getAge().equals("70后")){
					sql.append(" and (i.age>'1970-01-01' and i.age<'1975-01-01' ) ");
				} else {
					sql.append(" and i.age<'1970-01-01' ");
				}
			}
			if(Utils.isNotEmpty(information.getGender()) && !information.getGender().equals("0")){
				sql.append(" and i.gender=:gender  ");
				map.put("gender", information.getGender());
			}
			if(Utils.isNotEmpty(information.getEducation())){
				if(information.getEducation().equals("博士")){
					sql.append(" and instr(i.education,'博士')>0  ");
				} else if(information.getEducation().equals("硕士")){
					sql.append(" and (instr(i.education,'硕士')>0 or instr(i.education,'研究生')>0 )  ");
				} else if(information.getEducation().equals("本科")){
					sql.append(" and instr(i.education,'本科')>0  ");
				} else if(information.getEducation().equals("大专")){
					sql.append(" and instr(i.education,'大专')>0  ");
				} else {
					sql.append(" and (instr(i.education,'博士')=0 and instr(i.education,'硕士')=0 " +
							"and instr(i.education,'研究生')=0 and instr(i.education,'本科')=0and instr(i.education,'大专')=0 ) ");
				}
				map.put("education", information.getEducation());
			}
			if(Utils.isNotEmpty(information.getKeywords())){
				sql.append(" and (instr(i.userNickName,:keywords)>0 or instr(i.nickname,:keywords)>0 or instr(i.phone,:keywords)>0) ");
				map.put("keywords", information.getKeywords());
			}
			if(Utils.isNotEmpty(information.getMarriage())){
				sql.append(" and i.marriage=:marriage  ");
				map.put("marriage", information.getMarriage());
			}
			if(Utils.isNotEmpty(information.getPic())){
				if (information.getPic().equals("有")) {
					sql.append(" and pic is not null and pic !=''  ");
				} else {
					sql.append(" and (pic is null or pic ='')  ");
				}
			}
			/*if(Utils.isNotEmpty(information.getPic())){
				sql.append(" and pic is not null and pic !=''  ");
			}*/
            if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
				sql.append(" order by i."+information.getSort()+" "+information.getOrder());
			} else {
				sql.append(" order by i.update_time desc");
			}
		}
		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}


	@Override
	public Integer infoStateNum(Information information) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Integer> rm = new SingleColumnRowMapper<Integer>(Integer.class);
		StringBuffer sql = new StringBuffer("select count(1) ");
		sql.append(" from a_information i ");
		sql.append(" where i.deleted=0 ");
//		sql.append(" and DATE_FORMAT(pack_date,'%Y-%m-%d') =DATE_FORMAT(:pack_date,'%Y-%m-%d') ");
		if(Utils.isNotEmpty(information)){
			if(Utils.isNotEmpty(information.getState())){
				sql.append(" and i.state=:state  ");
				map.put("state", information.getState());
			}
		}
		getMapParameter(sql, map);
		return jdbcTemplate.queryForObject(sql.toString(),map, rm);
	}

	@Override
	public List<Information> getByOpenid(Information information) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
        StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
		sql.append(",i.userAvatar,i.userNickName");
        sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.username createName ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 and i.openid=:openid ");
		map.put("openid", information.getOpenid());
		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public Information getById(Information information) {
		RowMapper<Information> rm = new BeanPropertyRowMapper<Information>(Information.class);
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql = new StringBuffer("select i.id,i.organization_id,i.openid");
		sql.append(",i.userAvatar,i.userNickName");
        sql.append(",i.user_id,i.nickname,i.gender,i.age");
		sql.append(",i.phone,i.marriage,i.education,i.occupation");
		sql.append(",i.car,i.house,i.pic,i.height");
		sql.append(",i.weight,i.comment,i.nativeplace,i.address");
		sql.append(",i.hobby,i.requirement,i.type,i.state,i.reward");
		sql.append(",i.create_time,i.create_user,i.update_time,i.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.username createName ");
        sql.append(" from a_information i ");
        sql.append(" inner join sys_user suser on suser.user_id=i.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=i.organization_id ");
        sql.append(" where i.deleted=0 and sogzn.deleted=0 and i.id=:id ");
		map.put("id", information.getId());
		getMapParameter(sql, map);
		return jdbcTemplate.queryForObject(sql.toString(), map, rm);
	}

	@Override
	public Settings getByType(Settings settings) {
		RowMapper<Settings> rm = new BeanPropertyRowMapper<Settings>(Settings.class);
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql = new StringBuffer("select ");
		sql.append("s.id,s.type,s.valnum");
        sql.append(" from a_settings s ");
        sql.append(" where 1=1 ");
		if(Utils.isNotEmpty(settings)){
			if(Utils.isNotEmpty(settings.getType())){
				sql.append(" and instr(s.type,:type)>0 ");
				map.put("type", settings.getType());
			}
//            if(Utils.isNotEmpty(information.getSort())&&Utils.isNotEmpty(information.getOrder())){
//				sql.append(" order by i."+information.getSort()+" "+information.getOrder());
//			} else {
//				sql.append(" order by i.create_time desc");
//			}
		}
		getMapParameter(sql, map);
		return jdbcTemplate.queryForObject(sql.toString(), map, rm);
	}


	@Override
	public boolean save(Information information, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("insert into a_information (");
        sql.append("organization_id,openid,user_id,nickname");
		sql.append(",userAvatar,userNickName");
		sql.append(",gender,age,phone,marriage");
		sql.append(",education,occupation,car,house");
		sql.append(",pic,height,weight,comment");
		sql.append(",nativeplace,address,hobby,requirement");
		sql.append(",type,state,reward,create_user,create_time,update_user,update_time) values ( ");
        sql.append(":organization_id,:openid,:user_id,:nickname");
		sql.append(",:userAvatar,:userNickName");
		sql.append(",:gender,:age,:phone,:marriage");
		sql.append(",:education,:occupation,:car,:house");
		sql.append(",:pic,:height,:weight,:comment");
		sql.append(",:nativeplace,:address,:hobby,:requirement");
		sql.append(",:type,:state,:reward,:create_user,now(),:update_user,now())");
        map.put("organization_id", loginUser.getOrganizationId() + "");
        map.put("openid", information.getOpenid());
        map.put("user_id", information.getUserId());
        map.put("nickname", information.getNickname());
        map.put("userAvatar", information.getUserAvatar());
        map.put("userNickName", information.getUserNickName());
        map.put("gender", information.getGender());
        map.put("age", information.getAge());
        map.put("phone", information.getPhone());
        map.put("marriage", information.getMarriage());
        map.put("education", information.getEducation());
        map.put("occupation", information.getOccupation());
        map.put("car", information.getCar());
        map.put("house", information.getHouse());
        map.put("pic", information.getPic());
        map.put("height", information.getHeight());
        map.put("weight", information.getWeight());
        map.put("comment", information.getComment());
        map.put("nativeplace", information.getNativeplace());
        map.put("address", information.getAddress());
        map.put("hobby", information.getHobby());
        map.put("requirement", information.getRequirement());
        map.put("type", "公开");
		map.put("state", "已审核");
//        map.put("type", information.getType());
//        map.put("state", information.getState());
        map.put("reward", information.getReward());
		map.put("create_user", loginUser.getUserId() + "");
		map.put("update_user", loginUser.getUserId() + "");
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean update(Information information, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update a_information set ");
        sql.append("openid=:openid,user_id=:user_id,nickname=:nickname ");
		sql.append(",userAvatar=:userAvatar,userNickName=:userNickName");
		sql.append(",gender=:gender,age=:age,phone=:phone ");
		sql.append(",marriage=:marriage,education=:education,occupation=:occupation ");
		sql.append(",car=:car,house=:house,pic=:pic ");
		sql.append(",height=:height,weight=:weight,comment=:comment ");
		sql.append(",nativeplace=:nativeplace,address=:address,hobby=:hobby ");
		sql.append(",requirement=:requirement,type=:type,state=:state,reward=:reward ");
		sql.append(",update_time=now(),update_user=:update_user where id=:id ");
        map.put("openid", information.getOpenid());
        map.put("user_id", information.getUserId());
        map.put("nickname", information.getNickname());
		map.put("userAvatar", information.getUserAvatar());
		map.put("userNickName", information.getUserNickName());
        map.put("gender", information.getGender());
        map.put("age", information.getAge());
        map.put("phone", information.getPhone());
        map.put("marriage", information.getMarriage());
        map.put("education", information.getEducation());
        map.put("occupation", information.getOccupation());
        map.put("car", information.getCar());
        map.put("house", information.getHouse());
        map.put("pic", information.getPic());
        map.put("height", information.getHeight());
        map.put("weight", information.getWeight());
        map.put("comment", information.getComment());
        map.put("nativeplace", information.getNativeplace());
        map.put("address", information.getAddress());
        map.put("hobby", information.getHobby());
        map.put("requirement", information.getRequirement());
		map.put("type", "公开");
		map.put("state", "已审核");
//        map.put("type", information.getType());
//        map.put("state", information.getState());
        map.put("reward", information.getReward());
		map.put("update_user", loginUser.getUserId() + "");
		map.put("id", information.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean updateUpTime(Information information, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update a_information set ");
		sql.append("update_time=now(),update_user=:update_user where id=:id ");
		map.put("update_user", loginUser.getUserId() + "");
		map.put("id", information.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean updateState(Information information, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update a_information set ");
		sql.append("state=:state ");
		sql.append(",update_time=now(),update_user=:update_user where id=:id ");
		map.put("state", information.getState());
		map.put("update_user", loginUser.getUserId() + "");
		map.put("id", information.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean remove(Information information, User loginUser) {
		int count = 0;
		Map<String, String> map = null;
		if(information.getId().length()>0){
			for(String ID : information.getId().split(",")){
				map  = new HashMap<String, String>();
				if(ID==null || ID.equals("")){ break; }
				StringBuffer sql =new StringBuffer("update a_information set deleted=1" +
						",update_user=:update_user, update_time=now() "
						+ " where id =:id ");
				map.put("update_user", loginUser.getUserId() + "");
				map.put("id", ID);
				getMapParameter(sql, map);
				count = jdbcTemplate.update(sql.toString(),map);
			}
		}
		return count > 0;
	}
}
